<?php

namespace core;


/*
 * Service Instance Helper
 *
 * @author Kevin - xuhuahai@dangdang.com
 * @version 1.0
 * @date Apr 18, 2015
 */
class ServiceInstanceFactory {
	
	/**
	 *
	 * @var array Array of saved caches for reusing
	 */
	protected static $instances = array ();
	
	/**
	 * 根据服务名和版本号，获取服务实例
	 * @param unknown $service
	 * @param unknown $version
	 */
	public static function getInstance($service_group, $service_name, $service_version) {
		$key = $service_group . '*' . $service_name . '*' . $service_version;
		if (isset ( self::$instances [$key] )) {
			return self::$instances [$key];
		}
		global $global_service_instances;
		if(array_key_exists($key,$global_service_instances)){
			$classname = $global_service_instances[$key];
			$class = new \ReflectionClass($classname);
			$instance = $class->newInstance();
			if(PROFILE != 'dev'){
				self::$instances [$key] = $instance;
			}
			return $instance;
		}else{
			return null;
		}
	}
	
	
}


